/**
 * @Author: Sagan
 * @Date: 2020/09/27 11:32
 */
package constant

import (
	"fmt"
)

var message = map[string]string{
	REQUIRE:       "%s require",
	INT:           "%s must be integer",
	FLOAT:         "%s must be float",
	BOOLEAN:       "%s must be bool",
	BOOLEAN_TRUE:  "%s must be bool value true",
	BOOLEAN_FALSE: "%s must be bool value false",
	ARRAY:         "%s must be array",
	EMAIL:         "%s not a valid email address",
	ALPHA:         "%s must be alpha",
	ALPHA_NUM:     "%s must be alpha-numeric",
	ALPHA_DASH:    "%s must be alpha-numeric, dash, underscore",
	CHS:           "%s must be chinese",
	CHS_NUM:       "%s must be chinese or numeric",
	CHS_ALPHA:     "%s must be chinese or alpha",
	CHS_ALPHA_NUM: "%s must be chinese,alpha-numeric",
	CHS_DASH:      "%s must be chinese,alpha-numeric,underscore, dash",
	IP:            "%s not a valid ip",
	IPV4:          "%s not a valid ipv4",
	IPV6:          "%s not a valid ipv6",
	JSON:          "%s not a valid json",
	JSON_ARRAY:    "%s not a valid json array",
	JSON_OBJECT:   "%s not a valid json object",
	IN:            "%s must be in %s",
	NOT_IN:        "%s be not in %s",
	BETWEEN:       "%s must between :1 - :2",
	NOT_BETWEEN:   "%s not between :1 - :2",
	LENGTH:        "size of %s must be %s",
	MAX:           "max size of %s must be %s",
	MIN:           "min size of %s must be %s",
	EQ:            "%s must equal %s",
	NEQ:           "%s be not equal %s",
	GT:            "%s must greater than %s",
	GTE:           "%s must greater than or equal %s",
	LT:            "%s must less than %s",
	LTE:           "%s must less than or equal %s",
}

func ParseMessage(k string, a ...interface{}) string {
	msg, has := message[k]

	if false == has {
		return ""
	}

	length := 0
	for _, v := range msg {
		if '%' == v {
			length++
		}
	}

	return fmt.Sprintf(msg, a[0:length]...)
}
